package com.ysx.member.controller;


import com.ysx.common.context.LoginMemberContext;
import com.ysx.common.repentity.CommonResp;
import com.ysx.common.repentity.PageResp;
import com.ysx.member.entity.PassengerQueryReq;
import com.ysx.member.entity.PassengerSaveReq;
import com.ysx.member.repentity.PassengerQueryResp;
import com.ysx.member.service.PassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/passenger")
@CrossOrigin
public class PssengerController {

    @Resource
    private PassengerService passengerService;

    /**
     * 保存乘客信息
     * @param req 乘客信息保存请求参数
     * @return 通用响应对象
     */
    @PostMapping("/save")
    public CommonResp <Object> save(@Valid PassengerSaveReq req)
    {
        passengerService.save(req);
        return new CommonResp<>();
    }
    /**
     * 查询乘客信息列表
     * @param req 乘客信息查询请求参数
     * @return 包含乘客信息列表的分页响应对象
     */
    @GetMapping ("/query-list")
    public CommonResp <PageResp<PassengerQueryResp>>queryList(@Valid PassengerQueryReq req)
    {
        req.setMemberId(LoginMemberContext.getId());
        PageResp<PassengerQueryResp> passengerQuerylist = passengerService.queryList(req);
        return new CommonResp<>(passengerQuerylist);
    }


    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id)
    {
        passengerService.delete(id);
        return new CommonResp();
    }


}
